let rec power x = function 
   0 -> 1
  |n -> x * power x (n-1);;

let rec application p x = match p with
    [] -> 0
  |(a, b)::l -> a*power x b + application l x;;

 application [(2,2);(2,3);(4,4)] 2;;



let rec add p1 p2 = match (p1,p2) with
    ([],p)| (p,[]) -> p
  | ((a1,b1)::l1,(a2,b2)::l2) -> if b1=b2 then 
                                    ((a1+a2), b1)::(add l1 l2)
                                 else if b1>b2 then
				   (a2,b2)::(add ((a1,b1)::l1) l2)
				 else 
				   (a1,b1)::(add l1 ((a2,b2)::l2));;

add [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;
                                    
  
let rec soustract p1 p2 = match (p1,p2) with
    ([],p)| (p,[]) -> p
  | ((a1,b1)::l1,(a2,b2)::l2) -> if b1=b2 then if a1=a2 then soustract l1 l2 
                                       else ((a1-a2), b1)::(soustract l1 l2)
                                 else if b1>b2 then
				   (0-a2,b2)::(soustract ((a1,b1)::l1) l2)
				 else 
				   (a1,b1)::(soustract l1 ((a2,b2)::l2));;	 

soustract [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)]


let rec deriv = function
    [] -> []
  | (a,b)::l -> (a*b,b-1)::(deriv l);;

deriv [(2,2);(2,3);(4,4)];;
